package com.jp.fm.scheduler;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.jp.fm.HomeFinanceRunner;
import com.jp.fm.dao.AccountDao;
import com.jp.fm.dao.CategoryDao;
import com.jp.fm.data.Account;
import com.jp.fm.service.CategoryService;

public class ScheduledAccountRefreshJob implements Job {

	@Override
	public void execute(final JobExecutionContext context)
			throws JobExecutionException {

		String accountName = (String) context.getMergedJobDataMap().get(
				"AccountName");

		AccountDao aDao = new AccountDao();
		Account acct = aDao.findByName(accountName);

		CategoryDao cDao = new CategoryDao();

		CategoryService cService = new CategoryService();
		cService.setCategoryDao(cDao);

		if (acct.isCanRefresh()) {
			HomeFinanceRunner.refreshAccountFromSource(acct, cService, cDao,
					aDao);
		}
	}
}
